package com.jack.leetcode.每日一题;

/*** 
 * @author zhangjie
 * @date 2020/4/17 21:27
 */
public class 跳跃游戏 {

    public boolean canJump(int[] nums) {
        int n = nums.length;
        if(nums[0] == 0){
            return nums.length == 1;
        }
        boolean result = true;
        for(int i = 1;i < n-1;i++){
            if(nums[i]==0){
                for(int j = 0;j<i;j++){
                    if(nums[j]>i-j){
                        break;
                    }
                    if(j==i-1){
                        result = false;
                        break;
                    }
                }
            }
        }
        if(nums[n-1] == 0){
            for(int j = 0;j<n-1;j++){
                if(nums[j]>=n-1-j){
                    break;
                }
                if(j==n-2){
                    result = false;
                    break;
                }
            }
        }
        return result;
    }
}
